package cn.outsourcing.supermarket.controller.backstage;

import cn.outsourcing.supermarket.common.Result;
import cn.outsourcing.supermarket.common.constants.BackstageGoodsConstants;
import cn.outsourcing.supermarket.common.utils.ResultUtils;
import cn.outsourcing.supermarket.dto.OnlyIdPayloadDTO;
import cn.outsourcing.supermarket.dto.backstage.*;
import cn.outsourcing.supermarket.service.BackstageGoodsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author gzkemays
 * @since 2021/11/3 20:05
 */
@RestController
@RequestMapping("/admin/goods")
public class GoodsController {
  @Resource BackstageGoodsService backstageGoodsService;

  @GetMapping("/onsale")
  public Result getOnSaleGoods(BackstageGoodsDTO dto) {
    return ResultUtils.simpleResult(
        backstageGoodsService.getGoods(
            dto, BackstageGoodsConstants.ON_SALE_GOODS, BackstageGoodsConstants.SORT_DEFAULT));
  }

  @GetMapping("/out")
  public Result getOutGoods(BackstageGoodsDTO dto) {
    return ResultUtils.simpleResult(
        backstageGoodsService.getGoods(
            dto, BackstageGoodsConstants.OUT_GOODS, BackstageGoodsConstants.SORT_DEFAULT));
  }

  @GetMapping("/drop")
  public Result getDropGoods(BackstageGoodsDTO dto) {
    return ResultUtils.simpleResult(
        backstageGoodsService.getGoods(
            dto, BackstageGoodsConstants.DROP_GOODS, BackstageGoodsConstants.SORT_DEFAULT));
  }

  @GetMapping("/sort")
  public Result getSortGoods(BackstageGoodsDTO dto) {
    return ResultUtils.simpleResult(backstageGoodsService.getSortGoods(dto, dto.getIndex()));
  }

  @GetMapping("/info")
  public Result getGoodsInfo(@Param("id") Integer id) {
    return ResultUtils.simpleResult(backstageGoodsService.getGoodsInfoById(id));
  }

  @PostMapping("/getGalleryList")
  public Result getGoodsGalleryList(@RequestBody BackstageGalleryDTO dto) {
    return ResultUtils.simpleResult(backstageGoodsService.getGalleryById(dto));
  }

  @GetMapping("/getAllSpecification")
  public Result getAllSpecification() {
    return ResultUtils.simpleResult(backstageGoodsService.getAllSpecification());
  }

  @GetMapping("/getAllCategory")
  public Result getAllCategory() {
    return ResultUtils.simpleResult(backstageGoodsService.getAllCategory());
  }

  @GetMapping("/getExpressData")
  public Result getExpressData() {
    return ResultUtils.simpleResult(backstageGoodsService.getExpressData());
  }

  @PostMapping("/store")
  public Result store(@RequestBody BackstageGoodsStoreDTO dto) {
    return ResultUtils.simpleResult(backstageGoodsService.store(dto));
  }

  @GetMapping("/indexShowStatus")
  public Result indexShowStatus(BackstageUpdateStatusDTO dto) {
    return ResultUtils.simpleResult(backstageGoodsService.indexShowStatus(dto));
  }

  @GetMapping("/saleStatus")
  public Result saleStatus(BackstageUpdateStatusDTO dto) {
    return ResultUtils.simpleResult(backstageGoodsService.saleStatus(dto));
  }

  @PostMapping("/checkSku")
  public Result checkSku(@RequestBody BackstageCheckSnDTO dto) {
    return ResultUtils.simpleResult(backstageGoodsService.checkSku(dto));
  }

  @PostMapping("/updateSort")
  public Result updateSort(@RequestBody BackstageUpdateSortDTO dto) {
    return ResultUtils.simpleResult(backstageGoodsService.updateSort(dto));
  }

  @PostMapping("/destory")
  public Result destroy(@RequestBody OnlyIdPayloadDTO dto) {
    return ResultUtils.simpleResult(backstageGoodsService.destroy(dto));
  }
}
